<?

#	This file is part of SmartWebIF.
#	
#	SmartWebIF is free software: you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation, either version 3 of the License, or
#	(at your option) any later version.
#	
#	SmartWebIF is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#	
#	You should have received a copy of the GNU General Public License
#	along with SmartWebIF.  If not, see <http://www.gnu.org/licenses/>.

$config = include 'config.php';
include 'functions.php';

if (($config["password"] <> '') and ($_COOKIE["auth"] <> $config["password"]) or ($_COOKIE["time"] <> '' and $_COOKIE["time"] < time())) die();

$sdvb = get_sdvb_info($config);

if ($sdvb["sdvb_path_err"]) $sdvb_err = '<tr><td></td><td><div class="ui-state-error">SmartDVB.exe not found! Make sure it is located inside the folder specified above.</div></td></tr>';
if ($sdvb["data_path_err"]) $data_err = '<tr><td></td><td><div class="ui-state-error">SmartDVB settings file not found! Make sure there is a folder named "settings" in the path above.</div></td></tr>';
if ($sdvb["vlc_path_err"]) $vlc_err = '<tr><td></td><td><div class="ui-state-error">The vlc executable was not found! Please ensure that vlc.exe is present in the location given above.</div></td></tr>';

$checked = '';
if ($config["norestart"] == '1') $checked = 'checked';

echo '
<!doctype html>
<html lang="en">
<head>
<script>
  $(function() {$(".b-save").button();});
  $(function() {
    $( "#accordion-settings" ).accordion({
	  collapsible: true,
	  heightStyle: "content"
	  });
	});
';
if (($sdvb["sdvb_path_err"]) or ($sdvb["data_path_err"]) or ($sdvb["vlc_path_err"])) echo '$("#accordion-settings .ui-accordion-content").show();';
echo '
</script>
</head>
';

echo '<body>';

echo '

<form method="get" action="index.php">
<div id="accordion-settings">
<h3> SmartWebIF </h3>
<div>
<table width="100%">
<tr><td align="right" width="250">Access password</td><td><input type="password" size="90" class="forms" name="password" value="'.$config["password"].'"></td><tr>
<tr><td></td><td><div class="highlight">Leave empty if you do not need it.</div></td></tr>
<tr><td align="right" width="250">DVB device hardware ID</td><td><input type="text" size="90" class="forms" name="hwid" value="'.stripslashes($config["hwid"]).'"></td><tr>
<tr><td></td><td><div class="highlight">If set, the DVB device can be restarted when SmartDVB is stopped. Requires administrator rights.</div></td></tr>
';
switch ($config["date_format"])
	{
	case '':
	echo '<tr><td align="right" width="250">Date format</td><td><select name="date_format" class="forms"><option selected value="1">DD/MM/YYYY</option><option value="2">MM/DD/YYYY</option><option value="3">YYYY/MM/DD</option></select></td><tr>';
	break;
	case 1:
	echo '<tr><td align="right" width="250">Date format</td><td><select name="date_format" class="forms"><option selected value="1">DD/MM/YYYY</option><option value="2">MM/DD/YYYY</option><option value="3">YYYY/MM/DD</option></select></td><tr>';
	break;
	case 2:
	echo '<tr><td align="right" width="250">Date format</td><td><select name="date_format" class="forms"><option value="1">DD/MM/YYYY</option><option selected value="2">MM/DD/YYYY</option><option value="3">YYYY/MM/DD</option></select></td><tr>';
	break;
	case 3:
	echo '<tr><td align="right" width="250">Date format</td><td><select name="date_format" class="forms"><option value="1">DD/MM/YYYY</option><option value="2">MM/DD/YYYY</option><option selected value="3">YYYY/MM/DD</option></select></td><tr>';
	break;
	}
echo '
<tr><td></td><td><div class="highlight">Date format used by the task scheduler. Use the format most similar to the one used on your computer.</div></td></tr>
</table>
</div>
<h3> SmartDVB </h3>
<div>
<table width="100%">
<tr><td align="right" width="250">SmartDVB application folder</td><td><input type="text" size="90" class="forms" name="sdvb_path" value="'.stripslashes($config["sdvb_path"]).'"></td><tr>
'.$sdvb_err.'
<tr><td></td><td><div class="highlight">The main SmartDVB application folder.</div></td></tr>
<tr><td align="right">SmartDVB data folder</td><td><input type="text" size="90" class="forms" name="data_path" value="'.stripslashes($config["data_path"]).'"></td></tr>
'.$data_err.'
<tr><td></td><td><div class="highlight">The SmartDVB data (user) folder - usually the same as the application folder.</div></td></tr>
</table>
</div>
<h3> VLC </h3>
<div>
<table width="100%">
<tr><td align="right" width="250">VLC application folder</td><td><input type="text" size="90" class="forms" name="vlc_path" value="'.stripslashes($config["vlc_path"]).'"></td></tr>
'.$vlc_err.'
<tr><td></td><td><div class="highlight">The main VLC folder.</div></td></tr>
<tr><td align="right">Embedded video stream configuration</td><td><input type="text" size="90" class="forms" name="stream1" value="'.$config["stream1"].'"></td></tr>
<tr><td></td><td><div class="highlight">The stream configuration string passed to VLC for the embedded video. Do not modify unless you know what you are doing!</div></td></tr>
<tr><td align="right">Embedded video stream URL</td><td><input type="text" size="90" class="forms" name="stream1_url" value="'.$config["stream1_url"].'"></td></tr>
<tr><td></td><td><div class="highlight">The URL used internally by SmartWebIF for the video stream. Insert the FQDN and port of the machine where SmartWebIF is installed.</div></td></tr>
<tr><td align="right">External video stream configuration</td><td><input type="text" size="90" class="forms" name="stream2" value="'.$config["stream2"].'"></td></tr>
<tr><td></td><td><div class="highlight">The stream configuration string passed to VLC for the external video. Change parameters to suit your network performance. TCP port must be the same with the one listed above.</div></td></tr>
<tr><td align="right">External video stream URL</td><td><input type="text" size="90" class="forms" name="stream2_url" value="'.$config["stream2_url"].'"></td></tr>
<tr><td></td><td><div class="highlight">The URL for the external player video stream. Insert the FQDN and port of the machine where SmartWebIF is installed.</div></td></tr>
<tr><td align="right">Keep VLC open on channel change</td><td><input type="hidden" name="norestart" value="0"><input '.$checked.' type="checkbox" class="form" name="norestart" value="1"></td></tr>
<tr><td></td><td><div class="highlight">For continuous streaming via an external player. Do not check if using embedded video!</div></td></tr>
</table>
</div>
</div>
<br>
<center><input class="b-save" type="submit" value="Save settings"><center>
</form>

</body>
</html>
';

?>